import {
  fromJS,
} from 'immutable';
import getWeather from '../../../api/todoList';

export const searchFocused = (val: any) => ({
  type: 'header/inputFocused',
  value: fromJS(val),
});

export const searchBlur = (val: any) => ({
  type: 'header/inputBlur',
  value: fromJS(val),
});

export const getSearchList = () => (dispatch:Function) => {
  // 获取搜索列表的换一下异步数据
  getWeather({ city: '烟台' }).then((res:any) => {
    const list = res.data.weather.map((item: { weather: any; }) => item.weather);
    const action = {
      type: 'header/searchListChangeWhenFocused',
      value: fromJS(list),
    };
    dispatch(action);
  });
};

export const mouseIn = () => ({
  type: 'header/mouseIn',
  value: true,
});

export const mouseOut = () => ({
  type: 'header/mouseOut',
  value: false,
});
